package com.ubs.training.server.aop;

import com.ubs.training.prod.server.service.LoggingService;
import com.ubs.training.prod.server.service.LoggingService;
import com.ubs.training.server.service.ContactService;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.aspectj.lang.ProceedingJoinPoint;

import javax.annotation.Resource;
import java.lang.annotation.Retention;

/**
 * Created with IntelliJ IDEA.
 * User: xubuntu
 * Date: 8/24/12
 * Time: 5:11 AM
 * To change this template use File | Settings | File Templates.
 */
@Aspect
@Component
public class ContactLoggingAdvice extends AbstractLoggingAdvice {

    @Around ("execution(* com.ubs.training.server.dao.impl.jdbc.NamedParamContactDaoImpl.*(..))")
    public Object processAddOrUpdate(ProceedingJoinPoint pjp) throws Throwable {


        String s = pjp.getSignature().getName();
        if (s.equals("add")) {
            svc.logEvent(ContactService.USER_REQUESTS_CONTACT_ADD);

        } else if (s.equals("update")) {
            svc.logEvent(ContactService.USER_REQUESTS_CONTACT_UPDATE);

        }
       return pjp.proceed();

    }




    @Around("execution(* com.ubs.training.server.service.ContactService.*(..))")
    public Object processAnotherAction(ProceedingJoinPoint pjp) throws Throwable {


        String s = pjp.getSignature().getName();
         if (s.equals("getAllContacts")) {
            svc.logEvent(ContactService.USER_REQUESTS_ALL_CONTACTS);

        } else if (s.equals("getAllContactsByClientID")) {
            svc.logEvent(ContactService.USER_REQUESTS_ALL_CONTACTS_OF_CLIENT);

        } else if (s.equals("getContactByID")) {
            svc.logEvent(ContactService.USER_REQUESTS_A_CONTACT_BY_ID);

        } else if (s.equals("deleteContact")) {
            svc.logEvent(ContactService.USER_REQUESTS_CONTACT_DELETE);

        } else if (s.equals("save"))  {
            svc.logEvent(ContactService.USER_REQUESTS_CONTACT_SAVE);
        }
        return pjp.proceed();
    }


/*
    @Around("execution(* com.ubs.training.server.service.ContactService.save*(..))")
    public void processSave(ProceedingJoinPoint pjp) throws Throwable {
            pjp.proceed();
        svc.logEvent("AOP with Contacts working - saving ");
    }*/



}


